package com.zhanglu.fun.services.website.forum.thread;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zhanglu.fun.services.website.bean.request.ForumThreadRequest;
import com.zhanglu.fun.services.website.common.ResultResponse;
import com.zhanglu.fun.services.website.security.Secured;

import lombok.extern.slf4j.Slf4j;

/**
 * @description
 * @Auther zhanglu
 * @Date 2017/8/21 下午3:12
 */
@RestController
@Slf4j
public class ThreadRouter {
    @Autowired
    private ThreadService threadService;

    @GetMapping("/forum/threads")
    public ResultResponse getForumThreads(ForumThreadRequest forumThread) {
        log.debug("getForumThreads receive params:[forumThread json:{}]", forumThread.toString());
        return threadService.getForumThreads(forumThread);
    }

    @Secured({ "NORMAL", "ADMINISTRATOR", "VIP", "SUPER_ADMIN" })
    @PutMapping("/forum/thread")
    public ResultResponse addForumThread(@RequestBody ForumThreadRequest forumThread) {
        log.debug("addForumThread receive params:[forumThread json:{}]", forumThread.toString());
        return threadService.addForumThread(forumThread);
    }

    @Secured({ "NORMAL", "ADMINISTRATOR", "VIP", "SUPER_ADMIN" })
    @PostMapping("/forum/thread")
    public ResultResponse updateForumThread(@RequestBody ForumThreadRequest forumThread) {
        log.debug("updateForumThread receive params:[forumThread json:{}]", forumThread.toString());
        return threadService.updateForumThread(forumThread);
    }

    @Secured({ "NORMAL", "ADMINISTRATOR", "VIP", "SUPER_ADMIN" })
    @DeleteMapping("/forum/thread")
    public ResultResponse deleteForumThread(@RequestParam("id") Long id) {
        log.debug("deleteForumThread receive params:[id is:{}]", id);
        return threadService.deleteForumThread(id);
    }
}
